cflags =  -g  -Wall -Wstrict-prototypes \
              -march=i386 -mregparm=3 \
              -include code16gcc.h \
              -fno-strict-aliasing -fomit-frame-pointer \
              -ffreestanding \
              -fno-toplevel-reorder\
              -fno-unit-at-a-time \
              -fno-stack-protector \
              -mpreferred-stack-boundary=2 \
              -mno-sse -mno-mmx -mno-sse2 -mno-3dnow \
              -pipe \
              -m32

aflags =  ${cflags} -D__ASSEMBLY__

vm_path=/home/yanglei/rlinux/vm/

default: simple_boot simple_elf

simple_boot: boot.s
	gcc -c boot.s -o boot.s.o
	ld -N -Ttext 0x7c00 -s --oformat binary  -o boot.bin  boot.s.o
	mdel c:/boot.bin
	mcopy boot.bin c:/boot.bin

simple_elf: elf.s.o
	ld -N -T elf.ld -o bootelf.bin $?
	mdel c:/bootelf.bin
	mcopy bootelf.bin c:/bootelf.bin

elf.s.o: elf.s
	gcc ${aflags} -c $< -o $@

# 如果使用 boch 虚拟机，可以使用它将文件写入到软盘镜像当中
bochs_boot_img: simple_boot
	dd if=boot.bin of=${vm_path}/a.img bs=512 count=1 conv=notrunc

clean:
	rm -f *.o
	rm -f *.bin
